#!/bin/bash
## master install

source ../config/hosts.conf
hostname $1
echo $1 > /etc/hostname

cat << EOF >> /etc/hosts
$master_ip  $master_name
$node1_ip   $node1_name
$node2_ip   $node2_name
EOF

yum install python-rhsm* -y

# 安装node 组件
yum install -y docker flannel kubernetes-node
#添加阿里云镜像加速器
mkdir -p /etc/docker
tee /etc/docker/daemon.json << EOF
{
  "registry-mirrors": ["https://wbuj86p5.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
systemctl enable docker


mv /etc/kubernetes/config   /etc/kubernetes/config_bak
cp ../config/master_config  /etc/kubernetes/config

mv /etc/kubernetes/kubelet /etc/kubernetes/kubelet_bak
cat << EOF > /etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_HOSTNAME="--hostname-override=$1"
KUBELET_API_SERVER="--api-servers=http://master:8080"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=""
EOF


systemctl enable kubelet.service
systemctl start kubelet.service
systemctl enable kube-proxy.service
systemctl start kube-proxy.service

#flanneld
mv /etc/sysconfig/flanneld /etc/sysconfig/flanneld_bak
cp ../config/flanneld /etc/sysconfig/flanneld

systemctl enable flanneld.service 
systemctl start flanneld.service 
systemctl restart kube-apiserver.service
systemctl restart kube-controller-manager.service
systemctl restart kube-scheduler.service

docker pull docker.io/googlecontainer/kubernetes-dashboard-amd64:v1.4.1
docker tag docker.io/googlecontainer/kubernetes-dashboard-amd64:v1.4.1   registry.access.redhat.com/rhel7/pod-infrastructure
